import { createRouter, createWebHistory } from 'vue-router'
import { ElMessage } from 'element-plus'

const routes = [
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/Login.vue'),
    meta: { title: '登录' }
  },
  {
    path: '/',
    component: () => import('@/layouts/MainLayout.vue'),
    redirect: '/home',
    children: [
      {
        path: 'home',
        name: 'Home',
        component: () => import('@/views/Home.vue'),
        meta: { title: '首页' }
      },
      {
        path: 'storage/:storageKey?',
        name: 'Storage',
        component: () => import('@/views/Storage.vue'),
        meta: { title: '文件列表' }
      },
      {
        path: 'module1',
        name: 'Module1',
        component: () => import('@/views/modules/Module1.vue'),
        meta: { title: '模块一' }
      },
      {
        path: 'module2',
        name: 'Module2',
        component: () => import('@/views/modules/Module2.vue'),
        meta: { title: '模块二' }
      },
      {
        path: 'module3',
        name: 'Module3',
        component: () => import('@/views/modules/Module3.vue'),
        meta: { title: '模块三' }
      },
      {
        path: 'module4',
        name: 'Module4',
        component: () => import('@/views/modules/Module4.vue'),
        meta: { title: '模块四' }
      },
      {
        path: 'module5',
        name: 'Module5',
        component: () => import('@/views/modules/Module5.vue'),
        meta: { title: '天气查询系统' }
      },
      {
        path: 'ai',
        name: 'AI',
        component: () => import('@/views/modules/AIModule.vue'),
        meta: { title: 'AI 智能助手' }
      }
    ]
  },
  {
    path: '/admin',
    component: () => import('@/layouts/AdminLayout.vue'),
    redirect: '/admin/storage',
    meta: { title: '后台管理' },
    children: [
      {
        path: 'storage',
        name: 'AdminStorage',
        component: () => import('@/views/admin/StorageManage.vue'),
        meta: { title: '存储源管理' }
      },
      {
        path: 'storage/edit/:id?',
        name: 'StorageEdit',
        component: () => import('@/views/admin/StorageEdit.vue'),
        meta: { title: '编辑存储源' }
      },
      {
        path: 'user',
        name: 'AdminUser',
        component: () => import('@/views/admin/UserManage.vue'),
        meta: { title: '用户管理' }
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 路由守卫 - 已忽略登录验证
router.beforeEach(async (to, from, next) => {
  // 设置页面标题
  document.title = to.meta.title ? `${to.meta.title} - 军神网盘` : '军神网盘'
  
  // 直接放行，不检查登录状态
  next()
})

export default router

